- ocaml-md5sums will now delete the registry file if, after an update,
authorStefano Zacchiroli <zack@debian.org>
Sat, 9 Jul 2005 15:58:08 +0000 (15:58 +0000)
committerStefano Zacchiroli <zack@debian.org>
Sat, 9 Jul 2005 15:58:08 +0000 (15:58 +0000)
  it no longer contains any entry (actually if it is empty)
- on removal update registry in prerm script instead of postrm one so
  that registry dir could be deleted by dpkg if empty
- bugfix in Makefile: scripts are installed again when creating
  debhelper package

Makefile
dh_ocaml
ocaml-md5sums.ml.in
postrm-ocaml [deleted file]
prerm-ocaml [new file with mode: 0644]

index 203e80bd27b67789de7139f3af96f75cfbf29930..d44e28b8f7e8b54be23a50f71fa4832678c6eb5a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ FED_SUMS = ocaml-nox.md5sums ocaml.md5sums ocaml-compiler-libs.md5sums
 OCAMLC = ocamlc
 OCAMLOPT = ocamlopt
 OCAML_LIBS = unix str
+SCRIPTS = postinst-ocaml prerm-ocaml
 
 all: ocaml-md5sums
 opt: ocaml-md5sums.opt
index 7eaa5e8623f042ebc60533656c0042e6e0efc0d0..9666137c4a8e839b8eca58e228643115c4a392e3 100755 (executable)
--- a/dh_ocaml
+++ b/dh_ocaml
@@ -72,9 +72,9 @@ imported units will instead be used as keys in the OCaml md5sums registry for
 retrieving dependency information for the package. Those information will then
 be used to fill the "${ocaml:Depends}" substvar.
 
-dh_ocaml takes also care of creating postinst and postrm autoscripts which
-update the global system registry (/var/lib/ocaml/md5sums/MD5SUMS) with the
-registry entry shipped by your package.
+dh_ocaml takes also care of creating postinst and prerm autoscripts which update
+the global system registry (/var/lib/ocaml/md5sums/MD5SUMS) with the registry
+entry shipped by your package.
 
 On non-library packages, dh_ocaml tries to guess the OCaml objects corresponding
 to shipped bytecode binaries and extract from them information about imported
@@ -250,7 +250,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
       . " | sort -k 2"  # optional pass, just for "pretty" printing
       . " > $tmp$md5dir/$package$md5ext");
     autoscript $package, "postinst", "postinst-ocaml";
-    autoscript $package, "postrm", "postrm-ocaml";
+    autoscript $package, "prerm", "prerm-ocaml";
     complex_doit "$omd5 --load-info $oinfo dep < $olist > $odeps"; #compute deps
     fill_ocaml_depends $package, $tmp, $odeps, 1, $runtime;
   } elsif (is_binary $package, $dh{L_PARAMS}) {  # ocaml binary package
index 3aafb209ed0cd212a8c1a70dd290d57ed068a454..dc5dceec1a5a6b95e0c652636fd5ad952ea1eff6 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2005, Stefano Zacchiroli <zack@debian.org>
  *
  * Created:        Wed, 06 Apr 2005 16:55:39 +0200 zack
- * Last-Modified:  Mon, 11 Apr 2005 10:39:58 +0200 zack
+ * Last-Modified:  Sat, 09 Jul 2005 17:40:44 +0200 zack
  *
  * This is free software, you can redistribute it and/or modify it under the
  * terms of the GNU General Public License version 2 as published by the Free
@@ -98,6 +98,8 @@ let read_stdin () =
   iter_in (fun s -> lines := s :: !lines) stdin;
   List.rev !lines
 
+let is_empty fname = (Unix.stat fname).Unix.st_size = 0
+
 (** {2 Auxiliary functions} *)
 
 (** loads info previously stored in a file using --dump-info and stores them in
@@ -200,17 +202,19 @@ let iter_registry f fname =
             fname !lineno)))
     fname
 
-(** @param fname file name of the registry file
+(** @param fname file name of the registry file, if fname does not exists an
+ * empty registry will be returned
  * @return an hashtbl mapping pairs <unit_name, md5sum> to pairs <package_name,
  * version_info>. E.g. ("Foo_bar", "74be7fa4320ebd9415f1c7cfc04c2d7b") ->
  * ("libfoo-ocaml-dev", ">= 1.2.3-4") *)
 let parse_registry fname =
   let registry = Hashtbl.create 1024 in
-  iter_registry
-    (fun ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version ->
-      Hashtbl.replace registry (unit_name, md5sum)
-        (dev_dep, runtime_dep, dep_version))
-    fname;
+  if Sys.file_exists fname then
+    iter_registry
+      (fun ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version ->
+        Hashtbl.replace registry (unit_name, md5sum)
+          (dev_dep, runtime_dep, dep_version))
+      fname;
   registry
 
 (** {2 Main functions, one for each command line action} *)
@@ -266,7 +270,8 @@ let update () =
     done
   with End_of_file ->
     Unix.closedir dir;
-    close_out registry
+    close_out registry;
+    if is_empty registry_file then Sys.remove registry_file
 
 (** {2 Main} *)
 
diff --git a/postrm-ocaml b/postrm-ocaml
deleted file mode 100644 (file)
index e6db7e7..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-if [ "$1" = "remove" ]; then
-  ocaml-md5sums update
-fi
diff --git a/prerm-ocaml b/prerm-ocaml
new file mode 100644 (file)
index 0000000..e6db7e7
--- /dev/null
@@ -0,0 +1,3 @@
+if [ "$1" = "remove" ]; then
+  ocaml-md5sums update
+fi